package org.wtframework.platform.server.service;

import java.io.File;
import java.util.UUID;

import org.openredhead.springx.core.server.service.FilePaths;
import org.openredhead.springx.core.server.util.ImageUtils;
import org.openredhead.springx.core.web.mvc.ajaxrpc.BasicAjaxRpcRemoteService;
import org.openredhead.springx.core.web.mvc.annotation.AjaxRpcMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 
 * <B>类描述：</B> （共用的开放方法Service） <br/><br/>
 * <B>作者：</B> 梁卓文<br/><br/>
 * <B>创建日期：</B> 2014年5月7日 上午11:04:09 
 *
 */
@Service
public class ImageCutService extends BasicAjaxRpcRemoteService {
	
	@Autowired
	protected ApplicationContext applicationContext;
	
	
//,String targetImage,Integer d,Integer x,Integer y,Integer width,Integer height
	@AjaxRpcMethod
	@ResponseBody
	public String abscut(String sourceImage,String targetImage,Integer d,Integer x,Integer y,Integer w,Integer h) {
		
		sourceImage = FilePaths.getSystemRootPath() + sourceImage;
		
		targetImage = FilePaths.getExposeTemporaryPath() + File.separator + UUID.randomUUID()+".jpg";
		 
		if(ImageUtils.abscut(sourceImage, targetImage, 0, x, y, w, h)){
             return targetImage;
		} else {
			 return "";
		}
		
	}

}
